<template>
  <div id="app">
    <h1>根组件</h1>
    <input type="text">
    <add-item></add-item>
    <hr>
    <sub-item></sub-item>
    <div>
      name: {{userInfo.name}}
      age: {{userInfo.age}}
      setting: {{$store.state.setting.title}}
      -- {{$store.state.setting.desc}}
      <button @click="setUserName('中韩')">设置名字</button>
    </div>
  </div>
</template>

<script>
import AddItem from './components/add-item.vue'
import SubItem from './components/sub-item.vue'
import { mapState, mapMutations } from 'vuex'

export default {
  name: 'app',
  data: function () {
    return {

    }
  },
  computed: {
    // 全局获取数据
    // ...mapSate(['count'])
    // 模块化获取数据
    ...mapState('user', ['userInfo'])
  },
  components: {
    AddItem,
    SubItem
  },
  methods: {
    ...mapMutations('user', ['setUserName'])
    // setUserName (name) {
    //   // 全局的
    //   // this.$store.commit('setUserName', name)
    //   // 使用命名空间 模块名/mutations名字
    //   this.$store.commit('user/setUserName', name)
    // }
  }
}
</script>

<style>
#app {
  width: 600px;
  margin: 20px auto;
  border: 3px solid #ccc;
  border-radius: 3px;
  padding: 10px;
}
</style>
